package com.start_eternity.oasissafewalk.comment;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Result<T> {
    private Integer code;//响应码，200 代表成功; 201代表审核; 0 代表失败
    
    private String message;  //响应信息 描述字符串
    
    private T data; //返回的数据

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(Integer code, T data) {
        this(code,"",data);
    }

    public Result(Integer code, String message) {
        this(code,message,null);
    }

    public Result(ErrorCode errorCode, String message) {
        this(errorCode.getCode(),message,null);
    }

    public Result(ErrorCode errorCode,T data) {
        this(errorCode.getCode(),errorCode.getMessage(),data);
    }

    public Result(ErrorCode errorCode, String message,T data) {
        this(errorCode.getCode(),message,data);
    }

    public Result(ErrorCode errorCode) {
        this(errorCode.getCode(),errorCode.getMessage(),null);
    }

    //增删改 成功响应
    public static Result success(){
        return new Result(200,"success",null);
    }
    //查询 成功响应
    public static Result success(Object data){
        return new Result(200,"success",data);
    }
    //失败响应
    public static Result error(String message){
        return new Result(0,message,null);
    }
    //审核
    public static Result examine(String message,Object data){
        return new Result(201,message,data);
    }
}
